public class QuickSort {
    public static void main(String[] args) {
        int[] nums = new int[]{5,2,3,1};
        sortArray(nums);
        for(int num:nums){
            System.out.println(num);
        }

    }
    public static void sortArray(int[] nums) {
        quickSort(nums,0,nums.length-1);
    }
    static void quickSort(int[] nums, int low, int high){
        if(low<high){
            int mid = getMiddle(nums,low,high);
            quickSort(nums,low, mid-1);
            quickSort(nums,mid+1,high);
        }

    }
    static int getMiddle(int[] nums, int low, int high){
        int mid = nums[low];
        while(low<high){
            while(low<high && mid<nums[high]){
                high--;
            }
            nums[low]=nums[high];
            while(low<high && mid>nums[low]){
                low++;
            }
            nums[high]=nums[low];
        }
        nums[low]=mid;
        return low;

    }
}
